package com.atguigu.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.atguigu.easyexcel.ExcelStudentDTO;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class ExcelStudentDTOListener extends AnalysisEventListener<ExcelStudentDTO> {
    List<ExcelStudentDTO> list = new ArrayList<>();
    @Override
    public void invoke(ExcelStudentDTO excelStudentDTO, AnalysisContext analysisContext) {
        //System.out.println("ExcelStudentDTOListener.invoke方法执行");
        list.add(excelStudentDTO);
        if (list.size()>=100){
            log.info("解析到一条数据:{}" ,excelStudentDTO);
            System.out.println("list="+list.size());
            list.clear();
        }
        // System.out.println("list = " + list);

    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完成了....");
        System.out.println("解析数据完成!");
        System.out.println("list.size() = " + list.size());
    }



   /* @Override
    public void invoke(ExcelStudentDTO excelStudentDTO, AnalysisContext analysisContext) {
        log.info("解析到一条数据:{}" ,excelStudentDTO);
        System.out.println("ExcelStudentDTOListener.invoke方法执行");
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        log.info("所有数据解析完成了....");
        System.out.println("解析数据完成!");
    }

    @Override
    public boolean hasNext(AnalysisContext analysisContext) {
        return false;
    }*/
}
